package com.offcn.service;

import com.offcn.dao.CourseDao;
import com.offcn.dao.CourseUserDao;
import com.offcn.dao.UserDao;
import com.offcn.entity.Course;
import com.offcn.entity.CourseUser;
import com.offcn.utils.PageTool;

import java.util.List;

/**
 * @author xyll1
 */
public class CourseUserService {
    CourseUserDao courseUserDao = new CourseUserDao();
    public int selectTotalCount(List<Object> uids) {
       return courseUserDao.selectTotalCount(uids);

    }


    public List<Object> selectUidsByName(String search) {
    return courseUserDao.selectUidsByName(search);
    }

    public List<CourseUser> findAllCourseUser(PageTool pageTool, List<Object> uids) {
        UserDao userDao =new UserDao();
        CourseDao courseDao = new CourseDao();
        List<CourseUser> cus = courseUserDao.findAllCourseUser(pageTool, uids);

        for (CourseUser courseUser : cus) {

            System.out.println(courseUser.getUid()+"--------------------------");
            Course courseByCid = courseDao.findCourseByCid(courseUser.getCid() + "");
            courseUser.setCourse(courseByCid);
            courseUser.setUser(userDao.findUserById(courseUser.getUid()+""));
        }
        return cus;
    }

    public boolean updateCourseUser(String id, String cid) {
        return courseUserDao.updateCourseUser(id,cid) >0;
    }

    public boolean deleteAllCourseUser(String ids) {
        return courseUserDao.deleteAllCourseUser(ids) >0;    }
}
